package com.example.dellpc.myapplication;

import android.annotation.TargetApi;
import android.content.DialogInterface;
import android.graphics.Color;
import android.os.Build;
import android.os.Bundle;
import android.support.v4.app.FragmentActivity;
import android.util.Log;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.Button;

import com.example.utils.SystemBarTintManager;
import com.jeremyfeinstein.slidingmenu.lib.SlidingMenu;

/**
 * Created by dellpc on 2016/8/11.
 */
public class SlidingMenuActivity extends FragmentActivity implements View.OnClickListener {
    private SlidingMenu slidingMenu;
    private Button button;

    @TargetApi(Build.VERSION_CODES.LOLLIPOP)
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.slidingmenu_activity);
        Log.d("111", Build.VERSION.SDK_INT + "");

//        if (Build.VERSION.SDK_INT>=21)
        if (android.os.Build.VERSION.SDK_INT > 18) {

            Window window = getWindow();
            window.setFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS,
                    WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);

            window.setFlags(
                    WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION,
                    WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION);
            // 创建状态栏的管理实例
            SystemBarTintManager tintManager = new SystemBarTintManager(this);
            // 激活状态栏设置
            tintManager.setStatusBarTintEnabled(true);
            // 激活导航栏设置
            tintManager.setNavigationBarTintEnabled(true);
            // 设置一个颜色给系统栏
            tintManager.setTintColor(Color.parseColor("#FFFF6666"));
        }


//        //透明导航栏
//        getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION);
        initView();

    }

    public void initSlidingMenu() {

        slidingMenu = new SlidingMenu(this);
        slidingMenu.setMode(SlidingMenu.LEFT);
        slidingMenu.setTouchModeAbove(SlidingMenu.LEFT);
        slidingMenu.setShadowDrawable(R.drawable.shadow);
        slidingMenu.setBehindOffset(200);
        slidingMenu.setFadeDegree(0.50f);
        slidingMenu.attachToActivity(this, SlidingMenu.SLIDING_CONTENT);
        slidingMenu.setMenu(R.layout.slidingmenu_activity);

        getSupportFragmentManager().beginTransaction().replace(R.id.slidingmenumain, new SlidingMenuFragment()).commitAllowingStateLoss();

    }

    public void initView() {
        button = (Button) findViewById(R.id.btn_open);
        button.setOnClickListener(this);


        initSlidingMenu();


    }

    @Override
    public void onClick(View v) {

        int id = v.getId();

        switch (id) {
            case R.id.btn_open:
                slidingMenu.toggle();

                break;

            default:

        }

    }
}
